//package dsk.demo.product;
//
//import dsk.demo.product.entity.AutoSendMailConfigEntity;
//import dsk.demo.product.entity.CustomerLinkManEntity;
//import dsk.demo.product.entity.MailtempEntity;
//import dsk.demo.product.service.CustomerLinkManService;
//import dsk.demo.product.service.MailtempService;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.mail.SimpleMailMessage;
//import org.springframework.mail.javamail.JavaMailSender;
//import org.springframework.mail.javamail.JavaMailSenderImpl;
//
//import java.util.List;
//import java.util.Properties;
//
//
//@SpringBootTest
//public class 邮箱测试 {
//    @Autowired
//    private MailtempService mailtempService;
//
//    @Autowired
//    private CustomerLinkManService customerLinkManService;
//
//
//    @Test
//    public void fun() {
//        AutoSendMailConfigEntity entity = new AutoSendMailConfigEntity();
//        entity.setHscode("84212300");
//        entity.setCompanyId("0");
//        entity.setMailtempId(2l);
//        entity.setPassword("ezfADMeg3qF4hy3V");
//        entity.setStmp("smtp.sparkspace.huaweicloud.com");
//        entity.setUsername("tango@yinpeiauto.com");
//        sendMail(entity);
//    }
//
//
//    private void sendMail(AutoSendMailConfigEntity entity){
//        JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
//        javaMailSender.setHost(entity.getStmp());
//        javaMailSender.setUsername(entity.getUsername());
//        javaMailSender.setPassword(entity.getPassword());
//        javaMailSender.setDefaultEncoding("utf-8");
//        Properties javaMailProperties = new Properties();
//        javaMailProperties.setProperty("mail.smtp.auth","true");
//        javaMailProperties.setProperty("mail.smtp.starttls.enable","true");
//        javaMailProperties.setProperty("mail.smtp.starttls.required","true");
//        javaMailSender.setJavaMailProperties(javaMailProperties);
//        MailtempEntity byId = mailtempService.getById(entity.getMailtempId());
//        //获取当天的批次
//        String companyId = entity.getCompanyId();
//        List<CustomerLinkManEntity> autoSendLinkMan = customerLinkManService.getAutoSendLinkMan(companyId, entity.getHscode());
//        for (CustomerLinkManEntity customerLinkManEntity : autoSendLinkMan) {
//            try {
//                //创建SimpleMailMessage对象
//                SimpleMailMessage message = new SimpleMailMessage();
//                //邮件发送人
//                message.setFrom(entity.getUsername());
//                //邮件接收人
//                message.setTo(customerLinkManEntity.getEmail());
//                //邮件主题
//                message.setSubject(byId.getTitle());
//                //邮件内容
//                message.setText(byId.getContent());
//                //发送邮件
//                javaMailSender.send(message);
//            } catch (Exception e) {
//                System.out.println("发送邮件时发生异常！" + e);
//            }
//        }
//    }
//}
